//
//  HMMainViewController.swift
//  Faner_Weibo
//
//  Created by 范英强 on 16/1/21.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class HMMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        let tabBar = HMTabBar()
        
        tabBar.composeButtonClosure = { [weak self] in
            
            print(self?.view)
        }
        
        setValue(tabBar, forKeyPath: "tabBar")
        
        //首页
        addChildViewController(HMHomeTableViewController(), imgName: "tabbar_home", title: "首页")
        //消息
        addChildViewController(HMMessageTableViewController(), imgName: "tabbar_message_center", title: "消息")
        //发现
        addChildViewController(HMDiscoverTableViewController(), imgName: "tabbar_discover", title: "发现")
        //我的
        addChildViewController(HMProfileTableViewController(), imgName: "tabbar_profile", title: "我的")
        
     //   self.performSelector("dismiss", withObject: nil, afterDelay: 5)

        
    }
    
    func dismiss() {
        self.dismissViewControllerAnimated(true, completion: nil)
    }
    
    private func addChildViewController(childController: UIViewController,imgName: String, title: String){
        //设置图片
        childController.tabBarItem.image = UIImage(named: imgName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置选中图片
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置文字颜色
        
        childController.title = title
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        addChildViewController(HMNavigationController(rootViewController: childController))
        
    }
    
    deinit{
        print("拜拜")
    }


    
}
